package org.xs.web.http.i18n;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

import org.xs.web.util.Helpers;

public class MessageMap implements Map<String, String>{
	public Map<String, String> message;
	public String enJs = null;
	
	public MessageMap(Map<String, String> message){
		this.message = message;
	}

	@Override
	public void clear() {
	
	}
	@Override
	public boolean containsKey(Object key) {
		return false;
	}

	@Override
	public boolean containsValue(Object value) {
		return false;
	}

	@Override
	public Set<java.util.Map.Entry<String, String>> entrySet() {
		return null;
	}

	@Override
	public String get(Object key) {
		return message.get(key);
	}
	
	public String get(String key,String[] args){
		String value = get(key);
		if(value == null || value.length() < 2) return value;
		int i =0;
		for(String arg : args){
			value = value.replaceAll("\\{\\s*"+i+"\\s*\\}", arg);
			i++;
		}
		return value;
	}
	
	public synchronized String toJs(){
		if(enJs == null){
			StringBuilder sb = new StringBuilder();
			sb.append("function Locale(){");
			for(Map.Entry<String, String> entry: message.entrySet()){
				sb.append("this.").append(entry.getKey()).append(" = '").append((entry.getValue())).append("';\n");	
			}
			sb.append("}");
			sb.append("window.L = new Locale();");
			this.enJs = sb.toString();
		}
		return enJs;
	}
	
	@Override
	public boolean isEmpty() {
		return false;
	}

	@Override
	public Set<String> keySet() {
		return null;
	}

	@Override
	public String put(String key, String value) {
		return null;
	}

	@Override
	public void putAll(Map<? extends String, ? extends String> m) {
	}

	@Override
	public String remove(Object key) {
		return null;
	}

	@Override
	public int size() {
		return message.size();
	}

	@Override
	public Collection<String> values() {
		return null;
	}

}
